# encoding: utf-8
""" 
@version: v1.0 
@author: autumner 
@license: Apache Licence  
@contact: 18322313385@163.com 
@site:  https://gitee.com/autumner/pythoncookbook
@software: PyCharm 
@file: threading_barrage.py 
@time: 2019/7/31 上午11:27
@note:
线程阻塞
"""
import time
from threading import Thread

class CountDownTask:

    def __init__(self):

        self._runing = True

    def terminate(self):

        self._runing = False
        print('阻塞完成')

    def run(self, n, var):

        while self._runing and n > 0:
            print('T-minus', n, var)
            n -= 1
            time.sleep(5)


c = CountDownTask()

t = Thread(target=c.run, args=(10, '次'))
t.start()
time.sleep(20)
print('线程在运行状态？', t.is_alive())
c.terminate()
t.join()
print('线程在运行状态？', t.is_alive())
